package com.idealighter.game.games.errenniuniu.struct;

import com.google.common.collect.Lists;

import com.idealighter.game.games.common.AbstractTable;
import com.idealighter.game.games.common.niuniu.NiuNiuCard;

import java.util.Arrays;
import java.util.List;

/**
 * 二人牛牛牌桌 .
 *
 */
public class ErRenNiuNiuTable extends AbstractTable {
  // 所属房间
  public final ErRenNiuNiuRoom room;
  public final ErRenNiuNiuSeat seat1;
  public final ErRenNiuNiuSeat seat2;

  // 一副牌
  public final List<NiuNiuCard> cards = Arrays.asList(NiuNiuCard.values());
  // 下一个叫庄的玩家
  public long nextCallPlayer = 0;

  /**
   * 二人牛牛桌子.
   * 
   * @param id id.
   * @param room 房间.
   */
  public ErRenNiuNiuTable(int id, ErRenNiuNiuRoom room) {
    super(id);
    this.room = room;
    this.seat1 = new ErRenNiuNiuSeat(0, this);
    this.seat2 = new ErRenNiuNiuSeat(1, this);
  }

  /**
   * 庄家 .
   * 
   * @return 二人牛牛座位.
   */
  public ErRenNiuNiuSeat dealer() {
    if (seat1.dealer) {
      return seat1;
    } else if (seat2.dealer) {
      return seat2;
    }

    return null;
  }

  /**
   * 获取seat .
   * 
   * @param order .
   * @return
   */
  public ErRenNiuNiuSeat getSeat(byte order) {
    if (order == 0) {
      return seat1;
    } else if (order == 1) {
      return seat2;
    }

    return null;
  }

  /**
   * 重置牌桌 .
   */
  public void reset() {
    this.nextCallPlayer = 0;
  }

  @SuppressWarnings("unchecked")
  @Override
  public ErRenNiuNiuRoom room() {
    return room;
  }

  @Override
  public List<ErRenNiuNiuSeat> seats() {

    return Lists.newArrayList(seat1, seat2);
  }
}
